package recycle.impl;

import org.springframework.stereotype.Service;
import recycle.dao.ProductstandardMapper;
import recycle.pojo.Productstandard;
import recycle.service.ProductstandardService;
import recycle.utils.Page;
import recycle.vo.ProductstandardParam;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
* 描述：规格表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class ProductstandardServiceImpl implements ProductstandardService{
	@Resource
	private ProductstandardMapper productstandardMapper;
 	
 	/**
    * 描述：根据Id获取Productstandard对象
    * @param id
    */
    public Productstandard findById(Serializable standardId){
    	return productstandardMapper.findById(standardId);
    }
    /**
    * 描述：获取所有的Productstandard对象
    */
    public List<Productstandard> findAll(){
    	return productstandardMapper.findAll();
    }

	/**
    * 描述：新增保存Productstandard对象
    */
    public int save(Productstandard productstandard){
    	return  productstandardMapper.save(productstandard);
    }

	/**
    * 描述：根据Id删除Productstandard对象
    * @param id
    */
    public int delete(Serializable standardId){
    	return  productstandardMapper.delete(standardId);
    }
	
	/**
    * 描述：更新Productstandard对象
    */
    public int update(Productstandard productstandard){
    	return  productstandardMapper.update(productstandard);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Productstandard> query(ProductstandardParam param){
    	return  productstandardMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(ProductstandardParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = productstandardMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = productstandardMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

}
